<template>
  <j-modal
    :title="title"
    :width="1300"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <div>
        <a-form :form="form">
          <a-row>
            <div style="width: 100%;text-align: center;font-size: 30px;font-weight: 600;margin-bottom: 20px">《物资入库单》
            </div>
            <a-col :xs="24" :sm="12">
              <a-form-item label="单据编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input disabled="true" v-decorator="['orderCode']" placeholder="系统自动生成"></a-input>
              </a-form-item>
            </a-col>
            <!--          <a-col :xs="24" :sm="12" v-show="!disableSubmit" >-->
            <a-col :xs="24" :sm="12" v-show="false">
              <a-form-item label="物资类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-radio-group @change="getAssetList" v-model:value="assetType">
                  <a-radio-button value="YHP01">易耗品</a-radio-button>
                  <a-radio-button value="BGYP01">办公用品</a-radio-button>
                  <a-radio-button value="CHWZ01">存货物资</a-radio-button>
                </a-radio-group>
              </a-form-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-item label="入库部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-select-ru-ku-depart disabled="true"
                                       v-decorator="['putDepartment', validatorRules.putDepartment]"></j-select-ru-ku-depart>
              </a-form-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-item label="仓库" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-select-cang-ku @change="test" :disabled="disableSubmit"
                                  v-decorator="['storage', validatorRules.storage]"></j-select-cang-ku>
              </a-form-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <!--            disableSubmit-->
              <a-form-item label="制单人" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-search-select-tag  disabled="true" v-decorator="['putUser', validatorRules.putUser]"
                                     :trigger-change="true" dict="sys_user,username,id"
                                     placeholder="请选择制单人"/>
                <!--              <j-select-assets></j-select-assets>-->
              </a-form-item>
            </a-col>


            <a-col :xs="24" :sm="12">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                label="验收单">
                <!--            <a-input placeholder="请输入图片" v-decorator="['image', {}]" />-->
                <!--            <j-image-upload  v-decorator="['image', {}]"></j-image-upload>-->
                <j-image-upload text="上传" v-decorator="['image', {}]" :isMultiple="true" :number="6"></j-image-upload>
              </a-form-item>

            </a-col>
            <a-col :xs="24" :sm="12"  v-show="!disableSubmit">

              <a-form-item label="请选择资产" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-select-assets  :assetTypeF="assetTypeF"  @change="handleView($event,props)"></j-select-assets>
              </a-form-item>
            </a-col>
            <!--          {{ this.zcglPutStorageAssetsTable.dataSource}}-->
            <!--          <button @click="add1()">添加数据</button>-->
          </a-row>
        </a-form>

        <!-- 子表单区域 -->
        <a-tabs v-model="activeKey" @change="handleChangeTabs">
<!--          {{zcglPutStorageAssetsTable.dataSource}}-->

          <a-tab-pane tab="物资明细表" :key="refKeys[0]" :forceRender="true">
            <j-editable-table
              @submit-add="appendToList"
              :ref="refKeys[0]"
              :disabled="disableSubmit"
              :loading="zcglPutStorageAssetsTable.loading"
              :columns="zcglPutStorageAssetsTable.columns"
              :dataSource="zcglPutStorageAssetsTable.dataSource"
              :maxHeight="300"
              :rowNumber="true"
              :assetValue="assetValue"
              :rowSelection="!disableSubmit"
              :actionButton="!disableSubmit"
              :showStatisticsRow="true"
              :hasStatisticsColumn="true"
            >
<!--              :rowSelection="!disableSubmit"-->
              <template v-slot:assetId="props">
                <a-select

                  v-if="props.text == assetValue"
                  :default-value="props.text"
                  placeholder="请选择物资名称"
                  style="width: 100%;color: red"
                  show-search
                  disabled="true"
                  optionFilterProp="label"
                  @change="(value) => handleProChange(value, props.rowId)"
                >
                  <a-select-option
                    v-for="(item, i) in assetList"
                    :key="i"
                    :value="item.id"
                    :label="item.name"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
                <a-select
                  v-else

                  :default-value="props.text"
                  placeholder="请选择物资名称"
                  style="width: 100%"
                  show-search
                  disabled="true"
                  optionFilterProp="label"
                  @change="(value) => handleProChange(value, props.rowId)"
                >
                  <a-select-option
                    v-for="(item, i) in assetList"
                    :key="i"
                    :label="item.name"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </template>
              <template v-slot:assetCode="props">
                <a-input :value="props.text" disabled/>
              </template>


              <template v-slot:assetType="props">
                <a-input :value="props.text" disabled/>
              </template>

              <template v-slot:assetSpecifications="props">
                <a-input :value="props.text" disabled/>
              </template>
              <template v-slot:assetUnit="props">
                <a-input :value="props.text" disabled/>
              </template>
              <template v-slot:assetPrice="props">
                <a-input :value="props.text" disabled/>
              </template>
              <!--            :src="getImgView(props.text)"-->
              <template v-slot:images="props">

                <img height="25px" alt=""
                     @click="view(getImgView(props.text))" :src="getImgView(props.text)"
                     style="max-width:80px;font-size: 12px;font-style: italic;"/>
              </template>

            </j-editable-table>
          </a-tab-pane>

        </a-tabs>
      </div>
    </a-spin>
    <div v-show="printFlag" style="position: absolute;top: 1px;background-color: whitesmoke;z-index: 100">

      <a-form :form="form">

        <table style="border-collapse: separate;" border="2" class="table_style">
          <div id="assessContent" ref="assessContent">
            <tr>
              <td colspan="2" style="text-align: center;font-size: 40px;font-weight: 600;line-height: 40px">物资入库单</td>
            </tr>
            <tr>
              <!--            <td style="width: 150px;text-align: center;font-size: 22px;line-height: 40px"><span>单据编码</span></td>-->
              <!--            <td style="height: 20px;width: 560px">{{ printData.orderCode }}</td>-->
              <td style="width: 150px;text-align: center;font-size: 22px;line-height: 40px">
                <a-form-item label="单据编码" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-top: 30px">
                  <a-input v-decorator="['orderCode']" placeholder="系统自动生成"></a-input>
                </a-form-item>
              </td>
            </tr>
            <tr>
              <!--            <td style="width: 150px;text-align: center;font-size: 22px;line-height: 40px"><p style="margin-top: 10px">入库部门</p></td>-->
              <!--            <td>-->
              <!--              <a-form-item    label="" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
              <!--                <j-select-ru-ku-depart style="border: none;font-size: 22px;position: absolute;top:-30px;" v-decorator="['putDepartment']"></j-select-ru-ku-depart>-->
              <!--              </a-form-item>-->
              <!--            </td>-->
              <td colspan="2" style="width: 150px;text-align: center;font-size: 22px;line-height: 40px">
                <a-form-item label="入库部门" :labelCol="labelCol" :wrapperCol="wrapperCol">

                  <j-select-ru-ku-depart
                    v-decorator="['putDepartment']"></j-select-ru-ku-depart>

                </a-form-item>
              </td>
            </tr>
            <tr>
              <td colspan="2"
                  style="width: 150px;text-align: center;font-size: 22px;margin-top: 34px;line-height: 40px">

                <a-form-item label="仓库" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-top: 30px">
                  <j-select-cang-ku @change="test"
                                    v-decorator="['storage']"></j-select-cang-ku>
                </a-form-item>
              </td>
            </tr>
            <tr>
              <td colspan="2" style="width: 150px;text-align: center;font-size: 22px;margin-top: 34px">
                <a-form-item label="制单人" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-top: 30px">
                  <j-search-select-tag disabled="false" v-decorator="['putUser', validatorRules.putUser]"
                                       :trigger-change="true" dict="sys_user,username,id"
                                       placeholder="请选择制单人"/>
                  <!--              <j-select-assets></j-select-assets>-->
                </a-form-item>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <a-tabs v-model="activeKey1" @change="handleChangeTabs">
                  <a-tab-pane tab="物资明细表" :key="refKeys1[0]" :forceRender="true">
                    <j-editable-table
                      :ref="refKeys1[0]"
                      :disabled="disableSubmit"
                      :loading="zcglPutStorageAssetsTable.loading"
                      :columns="zcglPutStorageAssetsTable.columnsNotPic"
                      :dataSource="zcglPutStorageAssetsTable.dataSource"
                      :maxHeight="3000"
                      :rowNumber="true"
                      :assetValue="assetValue"
                      :rowSelection="false"
                      :actionButton="!disableSubmit"
                      :showStatisticsRow="true"
                      :hasStatisticsColumn="true"
                      style="overflow-x: hidden;background-color: whitesmoke"
                    >
                      <template v-slot:assetId="props">

                        <a-select
                          v-if="props.text == assetValue"
                          :default-value="props.text"
                          placeholder="请选择物资名称"
                          style="width: 100%;color: red"
                          show-search
                          disabled="true"
                          @change="(value) => handleProChange(value, props.rowId)"
                        >
                          <a-select-option
                            v-for="(item, i) in assetList"
                            :key="i"
                            :value="item.id"
                          >
                            {{ item.name }}
                          </a-select-option>
                        </a-select>
                        <a-select
                          v-else
                          :default-value="props.text"
                          placeholder="请选择物资名称"
                          style="width: 100%"
                          show-search
                          disabled="true"
                          @change="(value) => handleProChange(value, props.rowId)"
                        >
                          <a-select-option
                            v-for="(item, i) in assetList"
                            :key="i"
                            :value="item.id"
                          >
                            {{ item.name }}
                          </a-select-option>
                        </a-select>
                      </template>
                      <template v-slot:assetCode="props">
                        <a-input :value="props.text"/>
                      </template>
                      <template v-slot:assetType="props">
                        <a-input :value="props.text"/>
                      </template>
                      <template v-slot:assetSpecifications="props">
                        <a-input :value="props.text"/>
                      </template>
                      <template v-slot:assetUnit="props">
                        <a-input :value="props.text"/>
                      </template>
                      <template v-slot:assetPrice="props">
                        <a-input :value="props.text"/>
                      </template>

                    </j-editable-table>
                  </a-tab-pane>

                </a-tabs>
              </td>
              <!-- 子表单区域 -->
            </tr>
          </div>
          <tr>
            <td colspan="2">
              <a-button style="margin-left: 87%" @click="printFlag=false">关闭</a-button>
              <a-button v-if="!addFlag" type="primary" @click="printHandleS">打印</a-button>
            </td>
          </tr>
        </table>
      </a-form>
    </div>


    <template slot="footer">
      <a-button @click="handleCancel">关闭</a-button>
      <a-button v-if="addFlag" @click="handleOk">确定</a-button>
      <a-button v-if="!addFlag" type="primary" @click="printHandle">打印</a-button>
    </template>


    <a-modal @cancel="picFlag=false" :visible="picFlag" width="1150px" height="670px"
             style="width: 1400px;height: 1100px">

      <div class="left" @mousewheel.prevent="rollImg" span="8">

        <img class="img" ref="imgDiv" @mousedown="move" id="img" :src="viewPic" height="600" alt=""
             style="max-width:1000px;font-size: 12px;font-style: italic;"/>
      </div>
      <template slot="footer">
        <a-button @click="picFlag=false">关闭</a-button>
      </template>
    </a-modal>
  </j-modal>
</template>

<script>
import html2canvas from 'html2canvas'
import printJS from 'print-js'
import store from '@/store'
import pick from 'lodash.pick'
import { FormTypes, getRefPromise } from '@/utils/JEditableTableUtil'
import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import JSelectAssets from '../../../components/jeecgbiz/JSelectAssets'
import { VALIDATE_NO_PASSED, validateFormAndTables } from '../../../utils/JEditableTableUtil'
import { getAction } from '../../../api/manage'
import { randomNumber } from '../../../utils/util'
import JImageUpload from '../../../components/jeecg/JImageUpload'
import JSelectCangKu from '../../../components/jeecgbiz/JSelectCangKu'
import JSelectRuKuDepart from '../../../components/jeecgbiz/JSelectRuKuDepart'
import ImagPreview from '../../jeecg/ImagPreview'
import { getFileAccessHttpUrl } from '@api/manage'

export default {
  name: 'ZcglPutStorageModal',
  mixins: [JEditableTableMixin],

  components: {
    ImagPreview,
    JSelectRuKuDepart,
    JSearchSelectTag, JSelectAssets, JImageUpload, JSelectCangKu
  },
  props: {


    assetTypeF: {
      type: Object,
      default: () => {
      }
    },
    addFlag: {
      type: Object,
      default: () => {
      }
    },
    assetValue: {
      type: Object,
      default: () => {
      }
    }
  },
  created () {
    // alert(this.getImgView("a.txt"))
    this.assetType = 'CHWZ01'
    // if(this.assetTypeF == 'CHWZ01'){
    //   this.assetTypeF = 3
    // }
    // if(this.assetTypeF == 'YHP01'){
    //   this.assetTypeF = 4
    // }
    // if(this.assetTypeF == 'BGYP01'){
    //   this.assetTypeF = 5
    // }
    // 过500毫秒调用
    setTimeout(() => {
      var data = {}
      data.storage = '1585440165014495234'
      this.form.setFieldsValue(pick(data, 'storage'))
    }, 1111)
    this.getAssetList()

  },
  data () {
    return {
      printFlag: false,

      printData: {},
      picFlag: false,
      viewPic: '',
      trueS: false,
      footer: '',
      assetType: 'CHWZ01',
      assetList: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 },
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 20 },
      },
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 0,
      validatorRules: {
        putDepartment: {
          rules: [
            { required: true, message: '请输入入库部门!' },
          ]
        },
        storage: {
          rules: [
            { required: true, message: '请输入入库的仓库!' },
          ]
        },
      },
      refKeys: ['zcglPutStorageAssets',],
      refKeys1: ['zcglPutStorageAssets1',],
      tableKeys: ['zcglPutStorageAssets',],
      activeKey: 'zcglPutStorageAssets',
      activeKey1: 'zcglPutStorageAssets1',
      // 入库的物资明细表
      zcglPutStorageAssetsTable: {
        loading: false,
        dataSource: [],
        columnsNotPic: [
          {
            title: '物资',
            key: 'assetId',
            type: FormTypes.select,
            dictCode: 'zcgl_asset_fixed,name,id',
            width: '200px',
            getData: true,
            disabled: true,
            allowSearch: true,
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            disabled: true,
            title: '物资编码',
            key: 'assetCode',
            slotName: 'assetCode',
            type: FormTypes.slot,
            width: '150px',
            placeholder: '请输入${title}',
            defaultValue: '',
          },

          {
            disabled: true,
            title: '物资分类',
            key: 'assetType',
            slotName: 'assetType',
            type: FormTypes.slot,
            width: '110px',
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          {

            key: 'assetSpecifications',
            slotName: 'assetSpecifications',
            title: '规格型号',

            type: FormTypes.slot,
            width: '200px',
            disabled: true,
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          {
            title: '单位',
            key: 'assetUnit',
            slotName: 'assetUnit',
            type: FormTypes.slot,
            width: '100px',
            disabled: true,
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          {
            title: '单价',
            key: 'assetPrice',
            type: FormTypes.inputNumber,
            width: '100px',
            jisuan: true,
            placeholder: '请输入${title}',
            defaultValue: '',
          },

          {
            title: '本次入库数量',
            key: 'assetAmount',
            type: FormTypes.inputNumber,
            width: '110px',
            placeholder: '请输入${title}',
            defaultValue: '',
            jisuan: true,

            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '备注说明',
            key: 'remark',
            type: FormTypes.input,
            width: '110px',
            placeholder: '请输入${title}',
            defaultValue: ''

          },
          // {
          //   title: '合计',
          //   key: 'total',
          //   type: FormTypes.normal,
          //   width: '150px',
          //   defaultValue: '',
          //
          // },

        ],
        columns: [
          {
            title: '主键',
            key: 'id',
            type: FormTypes.hidden,
            width: '200px',

          },
          {
            title: '物资',
            key: 'assetId',
            type: FormTypes.select,
            dictCode: 'zcgl_asset_fixed,name,id',
            width: '200px',
            getData: true,
            disabled: true,
            allowSearch: true,
            defaultValue: '',
            placeholder: '请选择${title}',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          // {
          //   title: '物资',
          //   key: 'assetId',
          //   type: FormTypes.slot,
          //   slotName: 'assetId',
          //   dictCode: 'zcgl_asset_fixed,name,id',
          //   width: '200px',
          //   getData: true,
          //   allowSearch: true,
          //   defaultValue: '',
          //   placeholder: '请选择${title}',
          //   validateRules: [{ required: true, message: '${title}不能为空' }]
          // },
          {
            disabled: true,
            title: '物资编码',
            key: 'assetCode',
            slotName: 'assetCode',
            type: FormTypes.slot,
            width: '150px',
            placeholder: '请输入${title}',
            defaultValue: '',
          },

          {
            disabled: true,
            title: '物资分类',
            key: 'assetType',
            slotName: 'assetType',
            type: FormTypes.slot,
            width: '110px',
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          {

            key: 'assetSpecifications',
            slotName: 'assetSpecifications',
            title: '规格型号',

            type: FormTypes.slot,
            width: '110px',
            disabled: true,
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          {
            title: '单位',
            key: 'assetUnit',
            slotName: 'assetUnit',
            type: FormTypes.slot,
            width: '100px',
            disabled: true,
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          {
            title: '单价',
            key: 'assetPrice',
            type: FormTypes.inputNumber,
            width: '100px',
            jisuan: true,
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          // {
          //   disabled: true,
          //   title: '仓库数量',
          //   key: 'trueCount',
          //   type: FormTypes.inputNumber,
          //   width: '110px',
          //   placeholder: '请输入${title}',
          //   defaultValue: ''
          // },
          // {
          //   disabled: true,
          //   title: '审核中数量',
          //   key: 'lcCount',
          //   type: FormTypes.inputNumber,
          //   width: '110px',
          //   placeholder: '请输入${title}',
          //   defaultValue: ''
          // },

          {
            title: '本次入库数量',
            key: 'assetAmount',
            type: FormTypes.inputNumber,
            width: '110px',
            placeholder: '请输入${title}',
            defaultValue: '',
            jisuan: true,

            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '备注说明',
            key: 'remark',
            type: FormTypes.input,
            width: '110px',
            placeholder: '请输入${title}',
            defaultValue: ''

          },

          // {
          //   title: '合计',
          //   key: 'total',
          //   type: FormTypes.normal,
          //   width: '150px',
          //   defaultValue: '',
          //
          // },
          {
            title: '图片',
            key: 'image',
            slotName: 'images',
            type: FormTypes.slot,
            width: '110px',
            defaultValue: '',
          },
        ]
      },
      url: {
        add: '/putstorage/zcglPutStorage/add',
        edit: '/putstorage/zcglPutStorage/edit',
        zcglPutStorageAssets: {
          list: '/putstorage/zcglPutStorage/queryZcglPutStorageAssetsByMainId'
        },
      },
      disableSubmit: false,
    }
  },
  methods: {

    appendToList: function(item) {
      // alert(JSON.stringify(item))
      this.zcglPutStorageAssetsTable.dataSource = item
    },

    filterOption(input, option) {

      alert(input)
// 重要的一步，可以console.log(input)看下输入的是啥
      this.name = input // 在此前是可以手动输入，但鼠标离开后，输入的内容不能在输入框内保存，将input的值给到a-select标签的v-model绑定的newSoftName即可实现将手动输入的值赋值给input
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      );
    },
    printHandleS () {
      html2canvas(this.$refs.assessContent, {

        backgroundColor: null,
        useCORS: true,
        windowHeight: document.body.scrollHeight
      }).then((canvas) => {

        const url = canvas.toDataURL()
        this.img = url
        printJS({

          printable: url,
          type: 'image',
          documentTitle: '',
          spanStyle: false
        })

      })
    },
    printHandle () {

      this.printFlag = true

      //在3000毫秒后跳出弹窗‘‘对不起, 要你久候’’

      // printJS({
      //
      //   printable: 'assessContent',
      //   type: 'html',
      //   targetStyles:['*'],
      // })
    },

    // 拖动图片
    move (e) {
      e.preventDefault()
      // 获取元素
      var left = document.querySelector('.left')
      var img = document.querySelector('.img')
      var x = e.pageX - img.offsetLeft
      var y = e.pageY - img.offsetTop
      // 添加鼠标移动事件
      left.addEventListener('mousemove', move)

      function move (e) {
        img.style.left = e.pageX - x + 'px'
        img.style.top = e.pageY - y + 'px'
      }

      // 添加鼠标抬起事件，鼠标抬起，将事件移除
      img.addEventListener('mouseup', function () {
        left.removeEventListener('mousemove', move)
      })
      // 鼠标离开父级元素，把事件移除
      left.addEventListener('mouseout', function () {
        left.removeEventListener('mousemove', move)
      })
    },
    // 缩放图片
    rollImg () {
      /* 获取当前页面的缩放比 若未设置zoom缩放比，则为默认100%，即1，原图大小 */

      var zoom = parseInt(this.$refs.imgDiv.style.zoom) || 100
      /* event.wheelDelta 获取滚轮滚动值并将滚动值叠加给缩放比zoom wheelDelta统一为±120，其中正数表示为向上滚动，负数表示向下滚动 */

      zoom += event.wheelDelta / 12
      /* 最小范围 和 最大范围 的图片缩放尺度 */

      if (zoom >= 80 && zoom < 500) {
        this.$refs.imgDiv.style.zoom = zoom + '%'
      }
      return false
    },
    view (text) {
      this.picFlag = true
      this.viewPic = text
    },
    /* 图片预览 */
    getImgView (text) {
      if (text && text.indexOf(',') > 0) {
        text = text.substring(0, text.indexOf(','))
      }
      return getFileAccessHttpUrl(text)
    },
    test () {

      this.form.validateFields((err, values) => {
        getAction('/zcgl/assetFixed/list').then((res) => {
          if (res.success) {
            this.assetList = res.result.records
          }
        })
      })

    },
    handleProChange (value, id) {
      let item = this.assetList.find((ele) => ele.id == value)
      let values = [
        {
          rowKey: id,
          values: {
            'assetId': item.id,
            'assetCode': item.code,
            'assetType': item.assetType,
            'assetSpecifications': item.specifications,
            'assetUnit': item.unit,
            'image': item.image,

          },
        },
      ]
      this.$refs.zcglPutStorageAssets.setValues(values)
    },
    getAssetList () {
      //
      // //此处      需要根据选择的物资类型去自动选择仓库    不需要人工去进行选择仓库选择仓库
      // var data = {}
      // if (this.assetType == 'YHP01') {
      //   data.storage = '1585440063688499202'
      //
      // }
      // if (this.assetType == 'BGYP01') {
      //
      //   data.storage = '1585440106449428481'
      //
      // }
      // if (this.assetType == 'CHWZ01') {
      //   //存货物资的id 去数据库里面找
      //   data.storage = '1585440165014495234'
      //
      // }
      // this.form.setFieldsValue(pick(data, 'storage'))
      // getAction('/zcgl/assetFixed/list', { 'assetType': this.assetType, 'pageNo': 1, 'pageSize': 3000 }).then((res) => {
      //   if (res.success) {
      //
      //     this.assetList = res.result.records
      //
      //   }
      // })
    },

    handleView (a, b) {
      // alert(JSON.stringify(this.zcglPutStorageAssetsTable.dataSource))
      getAction('/zcgl/assetFixed/getMulFixed', { id: a }).then((res) => {
        if (res.success) {
          for (let i = 0; i < res.result.length; i++) {
            var item = res.result[i]
            var type = item.assetType
            if (item.assetType.indexOf('YHP01')!=-1 ) {
              type = '易耗品'
            }
            if (item.assetType.indexOf('BGYP')!=-1) {
              type = '办公用品'
            }
            if (item.assetType.indexOf('CHWZ')!=-1) {
              type = '存货物资'
            }



              if(item.assetType != this.assetTypeF){

                alert("物资类型和当前领用单类型不匹配，请重新选择！")
                return
              }






            if (JSON.stringify(this.zcglPutStorageAssetsTable.dataSource).indexOf(item.id) == -1) {
              //存在就不做处理吧
              this.zcglPutStorageAssetsTable.dataSource.push({
                assetId: item.id,
                assetUnit: item.unit,
                assetName: item.name,
                assetPrice: item.price,
                assetCode: item.code,
                assetSpecifications: item.specifications,
                assetType: type,
                image: item.image
              })
            }

          }

        }
      })

      // this.zcglPutStorageAssetsTable.dataSource[b.index].assetId = a

    },
    /** 生成id */
    generateId (rows) {
      if (!(rows instanceof Array)) {
        rows = this.rows || []
      }
      let timestamp = new Date().getTime()
      return `${this.caseId}${timestamp}${rows.length}${randomNumber(6)}${this.tempId}`
    },
    /** push 一条数据 */
    push (record, update = true, rows, insertIndex = null, setDefaultValue = true) {
      return this._pushByDataSource([record], [insertIndex], update, rows, setDefaultValue)
    },
    add1 () {

      this.zcglPutStorageAssetsTable.dataSource.push({
        assetUnit: 111,
        assetId: '1429652418592813057'

      })
      // this.add()
    },

    /** 调用完edit()方法之后会自动调用此方法 */
    editAfter () {
      setTimeout(() => {

        let usercode = store.getters.userInfo.id
        let currentCompanyId = store.getters.userInfo.currentCompanyId
        //自动赋值  当前登陆人1   和当前部门

        if (this.model.id) {
          let fieldval = pick(this.model, 'orderCode', 'putDepartment', 'storage', 'putUser', 'image')
          this.$nextTick(() => {
            this.form.setFieldsValue(fieldval)
          })
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.zcglPutStorageAssets.list, params, this.zcglPutStorageAssetsTable)
        } else {


          let usercode = store.getters.userInfo.id
          //根据code去获取小部门的ID
          let currentCompanyId = store.getters.userInfo.orgCode
          getAction('/sys/sysDepart/getDepartByCode', {orgCode:currentCompanyId}).then((res) => {
            if (res.success) {
              currentCompanyId = res.result.id
              this.model.putUser = usercode
              this.model.putDepartment = currentCompanyId


              if(this.model.id){


              }else{
                let fieldval = pick(this.model, 'orderCode', 'putDepartment', 'storage', 'putUser', 'image')
                this.$nextTick(() => {
                  this.form.setFieldsValue(fieldval)
                })
              }
              // 加载子表数据
              if (this.model.id) {
                let params = { id: this.model.id }
                this.requestSubTableData(this.url.zcglPutStorageAssets.list, params, this.zcglPutStorageAssetsTable)
              }
            }
          })
        }
      },100)



    },
    /** 确定按钮点击事件 */
    handleOk () {
      let self = this
      this.$confirm({
        title: '确认提示',
        content: `是否确认入库，入库后不可编辑（只可入负数库存冲抵）？`,
        okType: 'danger',
        onOk () {

          /** 触发表单验证 */
          self.getAllTable().then(tables => {
            /** 一次性验证主表和所有的次表 */
            return validateFormAndTables(self.form, tables)
          }).then(allValues => {

            if (typeof self.classifyIntoFormData !== 'function') {
              throw self.throwNotFunction('classifyIntoFormData')
            }
            let formData = self.classifyIntoFormData(allValues)
            if(formData.storage == null ||  formData.storage == ''){
              alert("请选择仓库")
              return
            }




            // //此处新增自动入库
            // alert(JSON.stringify(formData))
            //
            // for (let i = 0; i < formData.zcglPutStorageAssetsTable.length; i++) {
            //   var item = formData.zcglPutStorageAssetsTable[i];
            //
            //  httpAction("/zcgl/zcglTypeSettings/list", {"name":a.zcglRecipientsAssetsList[0].chwzType  }, 'post').then((res) => {
            //
            //
            //
            //  })
            //
            // }


            // 发起请求

            return self.request(formData)
          }).catch(e => {
            if (e.error === VALIDATE_NO_PASSED) {
              // 如果有未通过表单验证的子表，就自动跳转到它所在的tab
              self.activeKey = e.index == null ? self.activeKey : self.refKeys[e.index]
            } else {
              console.error(e)
            }
          })
        }
      })

    },
    /** 整理成formData */
    classifyIntoFormData (allValues) {
      let main = Object.assign(this.model, allValues.formValue)
      return {
        ...main, // 展开
        zcglPutStorageAssetsList: allValues.tablesValue[0].values,
      }
    },
    validateError (msg) {
      this.$message.error(msg)
    },
    popupCallback (row) {
      this.form.setFieldsValue(pick(row, 'orderCode', 'putDepartment', 'storage', 'putUser'))
    },

  }
}
</script>

<style scoped>
.action-button > ant-btn ant-btn-primary {
  display: none !important;

}

.table_style {
  width: 100%;
  height: auto;
}

.table_style tr td {
  text-align: center;
}
</style>